import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:ts_app_dart/utils/request.dart';
// import 'package:flutter_swiper/flutter_swiper.dart';

class WeatherPage extends StatefulWidget {
  const WeatherPage({Key key}) : super(key: key);

  @override
  _WeatherPageState createState() => _WeatherPageState();
}

class _WeatherPageState extends State<WeatherPage> {
  List<Map> list = [
    {
      "cy": 101180101,
      "id": 3523,
      "cityname": "登封",
    },
    {
      "cy": 101271101,
      "id": 4667,
      "cityname": "翠屏",
    },
    {
      "cy": 101270101,
      "id": 4583,
      "cityname": "双流",
    }
  ];
  Map currentVal = {"cityname": "翠屏"};
  List<Map> imageList = [
    {"url": "https://www.itying.com/images/flutter/1.png"},
    {"url": "https://www.itying.com/images/flutter/2.png"},
    {"url": "https://www.itying.com/images/flutter/3.png"},
    {"url": "https://www.itying.com/images/flutter/4.png"}
  ];

  void fetchState() async {
    final dio = Dio();
    Response response;
    response = await dio.post('http://send.wxbus163.cn/weather/getToday',
        data: FormData.fromMap({
          "cityid": 3523,
        }));
    // response = await dio.get('http://send.wxbus163.cn/weather/getCityList',
    //     options: Options(headers: {'Content-Type': 'multipart/form-data'}));
    print(response.data);
    print(response.data.runtimeType);
    print("-----cityid get------");
    // var model = ModelWeather.fromJson(response.data);
    // print(model);
    response = await dio.get('https://petstore.swagger.io/v2/swagger.json');
    print(response.data['externalDocs']);
    print(response.runtimeType);
  }

  @override
  void initState() {
    super.initState();
    // fetchState();
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    HttpUtils.post('http://send.wxbus163.cn/weather/getToday', data: {
      "cityid": 3523,
    }).then((value) {
      print(value.data.runtimeType);
      // var model = ModelWeather.fromJson(value);
      // print(model);
      final payload = json.decode(value.toString());
      // final payload = json.decode(value.data);
      print(payload.runtimeType);
      setState(() {
        currentVal = payload['list'];
      });
      print(currentVal['cityname']);
    });
    HttpUtils.get('http://t.weather.itboy.net/api/weather/city/101010100')
        .then((value) {
      print('value.runtimeType');
      print(value.data['cityInfo']);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text('天气预报'),
        ),
        // body: SafeArea(
        //   child: Swiper(
        //     itemBuilder: (BuildContext context, int index) {
        //       // 配置图片地址
        //       return SingleChildScrollView(
        //         child: Column(children: [
        //           Image.network(
        //             imageList[index]["url"],
        //             fit: BoxFit.fill,
        //           ),
        //           Image.asset(
        //             'images/light_screen.png',
        //             fit: BoxFit.fill,
        //           ),
        //           Image.network(
        //             imageList[index]["url"],
        //             fit: BoxFit.fill,
        //           ),
        //         ]),
        //       );
        //     },
        //     // 配置图片数量
        //     itemCount: imageList.length,
        //     // 底部分页器
        //     pagination: SwiperPagination(),
        //   ),
        // ),
        body: SafeArea(
          child: PageView(
            children: <Widget>[
              Container(
                color: Colors.red,
                child: Center(
                  child: Text('Page 1'),
                ),
              ),
              Container(
                color: Colors.blue,
                child: Center(
                  child: Text('Page 2'),
                ),
              ),
              Container(
                color: Colors.green,
                child: Center(
                  child: Text('Page 3'),
                ),
              ),
            ],
          ),
        ),
        // body: SafeArea(
        //   child: Swiper(
        //     itemBuilder: (BuildContext context, int index) {
        //       // 配置图片地址
        //       return Image.network(
        //         imageList[index]["url"],
        //         fit: BoxFit.fill,
        //       );
        //     },
        //     // 配置图片数量
        //     itemCount: imageList.length,
        //     // 底部分页器
        //     pagination: SwiperPagination(),
        //     // 自动轮播
        //     autoplay: true,
        //   ),
        // ),
        );
  }
}
